﻿using Authorit.API.Configuration;
using SyncHeadings.Properties;

namespace SyncHeadings
{
	/// <summary>
	/// Implements support for reading the configuration settings file for the plugin
	/// </summary>
	public class Config
	{
		#region Fields (7) 

		/// <summary>
		/// Backing field for the <see cref="FormShowIcon"/> property
		/// </summary>
		private bool formShowIcon;
		/// <summary>
		/// Backing field for the <see cref="FormShowVersion"/> property
		/// </summary>
		private bool formShowVersion;
		/// <summary>
		/// Backing field for the <see cref="LogFileName"/> property
		/// </summary>
		private string logFileName;
		/// <summary>
		/// Backing field for the MinimumSelectedObjects property
		/// </summary>
		private int minimumSelectedObjects;
		/// <summary>
		/// Backing field for the <see cref="NLogConfigFileName"/> property
		/// </summary>
		private string nLogConfigFileName;
		/// <summary>
		/// Backing field for the <see cref="ToolbarPluginName"/> property
		/// </summary>
		private string toolbarPluginName;
		/// <summary>
		/// Backing field for the <see cref="ToolbarTargetGroup"/> property
		/// </summary>
		private string toolbarTargetGroup;

		#endregion Fields 

		#region Constructors (1) 

		/// <summary>
		/// Initializes a new instance of the <see cref="Config"/> class.
		/// </summary>
		/// <seealso cref="ReadConfiguration"/>
		public Config()
		{
			ReadConfiguration();
		}

		#endregion Constructors 

		#region Properties (7) 

		/// <summary>
		/// Gets or sets a value that specifies whether the form will display an icon in the title bar
		/// </summary>
		public bool FormShowIcon
		{
			get { return formShowIcon; }
			set { formShowIcon = value; }
		}

		/// <summary>
		/// Gets or sets a value that specifies whether the form will display the version of the plugin
		/// </summary>
		public bool FormShowVersion
		{
			get { return formShowVersion; }
			set { formShowVersion = value; }
		}

		/// <summary>
		/// Gets or sets the name of the log file to which the plugin will write
		/// </summary>
		public string LogFileName
		{
			get { return logFileName; }
			set { logFileName = value; }
		}

		/// <summary>
		/// Gets or sets the minimum number of objects that the user must select to enable the plugin
		/// </summary>
		public int MinimumSelectedObjects
		{
			get { return minimumSelectedObjects; }
			set { minimumSelectedObjects = value; }
		}

		/// <summary>
		/// Gets or sets the file name of the NLog configuration file
		/// </summary>
		public string NLogConfigFileName
		{
			get { return nLogConfigFileName; }
			set { nLogConfigFileName = value; }
		}

		/// <summary>
		/// Gets or sets the plugin name for the toolbar button
		/// </summary>
		public string ToolbarPluginName
		{
			get { return toolbarPluginName; }
			set { toolbarPluginName = value; }
		}

		/// <summary>
		/// Gets or sets the toolbar group to which to add the button
		/// </summary>
		public string ToolbarTargetGroup
		{
			get { return toolbarTargetGroup; }
			set { toolbarTargetGroup = value; }
		}

		#endregion Properties 

		#region Methods (1) 

		// Public Methods (1) 

		/// <summary>
		/// Reads the configuration file for the plugin and sets values for the properties
		/// of this instance of the <see cref="Config"/> class.
		/// </summary>
		public void ReadConfiguration()
		{
			this.formShowIcon = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.FormShowIcon));
			this.formShowVersion = ConfigReader.GetSettingAsBoolean(ReflectionUtility.GetPropertyName(() => Settings.Default.FormShowVersion));
			this.logFileName = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Settings.Default.LogFileName));
			this.minimumSelectedObjects = ConfigReader.GetSettingAsInt32(ReflectionUtility.GetPropertyName(() => Settings.Default.MinimumSelectedObjects));
			this.nLogConfigFileName = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Settings.Default.NLogConfigFileName));
			this.toolbarPluginName = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Settings.Default.ToolbarPluginName));
			this.toolbarTargetGroup = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Settings.Default.ToolbarTargetGroup));
		}

		#endregion Methods 
	}
}